package com.t235.gc.auth.controller;

import com.t235.gc.AjaxResult;
import com.t235.gc.LayuiTreeNode;
import com.t235.gc.auth.service.SysMenuService;
import com.t235.gc.entity.SysMenu;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单表(SysMenu)表控制层
 *
 * @author makejava
 * @since 2021-03-24 08:45:40
 */
@RestController
@RequestMapping("sysMenu")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SysMenu selectOne(String id) {
        return this.sysMenuService.queryById(id);
    }

    @RequestMapping("roleMenus")
    public AjaxResult roleMenus(String roleNames) {
        List<SysMenu> sysMenus = sysMenuService.queryAllByRoleNames(roleNames);
        return AjaxResult.success(sysMenus);
    }

   /* @RequestMapping("userMenus")
    public AjaxResult userMenus(String username) {
        List<SysMenu> sysMenus = sysMenuService.queryAllByRoleUserName(username);
        return AjaxResult.success(sysMenus);
    }*/
    @RequestMapping("userMenus")
    public AjaxResult userMenus(String username) {
        List<LayuiTreeNode> sysMenus = sysMenuService.buildLayuiMenuTree(username);
        return AjaxResult.success(sysMenus);
    }
}
